Skip to content

Bug 1685123 docs for implementation of WebEx manifest sandbox - #44709

Open
rebloor wants to merge 5 commits into
mdn:mainfrom
rebloor:Bug-1685123-manifest-sandbox-docs
Open

Bug 1685123 docs for implementation of WebEx manifest sandbox#44709
rebloor wants to merge 5 commits into
mdn:mainfrom
rebloor:Bug-1685123-manifest-sandbox-docs

Conversation

@rebloor

@rebloor rebloor commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

Description

Add details of the sandbox manifest key for Bug 1685123 "implement manifest sandbox support". In addition to the new manifest key page for sandbox, the changes include:

  • updates the content security policy page and content_security_policy key page to link to the new sandboxmanifest key page.
  • addition of the sandboxmanifest key to the list of manifest keys.
  • a release note for Firefox 154.

Related issues and pull requests

Parallel BCD updates in mdn/browser-compat-data#30031

@rebloor
rebloor requested review from Rob--W and bacharakis July 13, 2026 23:49
@rebloor rebloor self-assigned this Jul 13, 2026
@rebloor
rebloor requested review from a team as code owners July 13, 2026 23:49
@rebloor
rebloor requested review from pepelsbey and removed request for a team July 13, 2026 23:49
@rebloor rebloor added the Content:WebExt WebExtensions docs label Jul 13, 2026
@github-actions github-actions Bot added Content:Firefox Content in the Mozilla/Firefox subtree size/m [PR only] 51-500 LoC changed labels Jul 13, 2026
@rebloor

rebloor commented Jul 13, 2026

Copy link
Copy Markdown
Contributor Author

@Rob--W is inclusion of the example on the manifest page sufficient, or would you prefer to pull that out into a separate "how to" page?

@github-actions

github-actions Bot commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

`sandbox.js` listens for messages from the popup, renders a template using the sandboxed library, and posts the result back:

```js
window.addEventListener("message", (event) => {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below I am showing a concrete snippet to validate messages. Can you include that here too, and prominently mention a link to the security-relevant best practices at https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns

Ideally we should have a dedicated section on this manifest page that clarifies how this feature should be used:

  • messages between the extension and sandboxed page should be strictly validated, with link to https://developer.mozilla.org/en-US/docs/Web/API/Window/postMessage#security_concerns
  • don't execute untrusted code. Although the extension does not have access to privileged APIs, the extension URL may identify the use of the extension and be abused for fingerprinting purposes.
  • don't use sandboxed pages with a relaxed CSP if your only objective is the use of WebAssembly. Instead, add 'wasm-unsafe-eval' to the extension's content_security_policy instead.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread files/en-us/mozilla/add-ons/webextensions/manifest.json/sandbox/index.md Outdated
Comment thread files/en-us/mozilla/firefox/releases/154/index.md Outdated
<html lang="en">
<head>
<meta charset="utf-8" />
<script src="templating-library.js"></script>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this intended as a placeholder example? The example on the page itself does not run because the definition of the file is missing.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's now a fully working example. However, after debugging an issue I found with Claude, it responded that "sandbox.js rejected every message with if (event.origin !== location.origin) — but a sandboxed page has an opaque origin (serializes to "null"), while the sender (popup.html) has a real moz-extension:// origin, so that check could never pass and the render would never happen. I replaced it with event.source !== window.parent (and added the matching check on the popup.js side, event.source !== sandbox.contentWindow), which validates the sender by window identity instead of origin — this is what MDN's own postMessage() security-concerns guidance recommends specifically because origin comparisons don't work for opaque-origin frames."

Comment thread files/en-us/mozilla/add-ons/webextensions/manifest.json/sandbox/index.md Outdated

Use the `sandbox` key to designate one or more of an extension's pages as **sandboxed pages**.

Sandboxed pages are loaded with a unique, opaque origin, instead of the extension's usual `moz-extension://` origin. As a result:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Link "opaque origin" to https://developer.mozilla.org/en-US/docs/Glossary/Origin#opaque_origin

Also add a bullet point mentioning that web platform APIs bound to the origin are unavailable. For some examples, see https://developer.mozilla.org/en-US/docs/Web/HTTP/Reference/Headers/Content-Security-Policy/sandbox#allow-same-origin

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


This makes the `sandbox` key useful for including a third-party library that relies on `eval()` or `new Function()`, such as some templating engines: load the library in a sandboxed page, and use `postMessage()` to send it data from, and return results to, the rest of the extension.

## Manifest V2 syntax

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be less confusing if we:

  • declare one overview, and emphasize for the sandbox.content_security_policy key that it is MV2 only
  • at that description, point to the section on content_security_policy.sandbox (on the same page) for the MV3 syntax
  • note that the content_security_policy.sandbox is MV3-only, and that for MV2 the other key has to be used?

This would enable us to add new manifest keys to sandbox without being forced to duplicate that documentation in two sections. I anticipate that we will likely have a new manifest sub key in sandbox as part of https://bugzilla.mozilla.org/show_bug.cgi?id=2053336

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, done

Comment thread files/en-us/mozilla/add-ons/webextensions/manifest.json/sandbox/index.md Outdated

A sandboxed page can be given a more permissive [content security policy (CSP)](#content_security_policy_for_sandboxed_pages) than the rest of the extension. This includes a CSP that permits [`eval()`](/en-US/docs/Web/JavaScript/Reference/Global_Objects/eval) and similar constructs that are blocked by an extension's [default content security policy](/en-US/docs/Mozilla/Add-ons/WebExtensions/Content_Security_Policy#default_content_security_policy). Because a sandboxed page can't use WebExtension APIs or reach the rest of the extension directly, this can be done without weakening the security of the extension as a whole.

This makes the `sandbox` key useful for including a third-party library that relies on `eval()` or `new Function()`, such as some templating engines: load the library in a sandboxed page, and use `postMessage()` to send it data from, and return results to, the rest of the extension.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The framing of template engine is likely copied from Chrome. Although that was a motivating factor back then (10+ years ago), it is hardly a relevant considerations now. These days such libraries are mostly designed to work even with a strict CSP. Let's drop the mention of templating libraries (the general reference to eval/Function are sufficient).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

rebloor and others added 2 commits July 27, 2026 04:31
@rebloor
rebloor requested a review from Rob--W July 26, 2026 19:08
rebloor added 2 commits July 27, 2026 07:10
…anifest-sandbox-docs' of ssh://github.com/rebloor/content into Bug-1685123-manifest-sandbox-docs
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Content:Firefox Content in the Mozilla/Firefox subtree Content:WebExt WebExtensions docs Firefox 154 size/m [PR only] 51-500 LoC changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants